import java.util.Stack;

/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer II 038. 每日温度
 * @author: WXY
 * @create: 2022-12-29 10:13
 * @Version 1.0
 **/


public class offer_twelve_dailyTemperatures {
    public static int[] dailyTemperatures(int[] temperatures) {
        Stack<Integer> stack = new Stack<>();
        int[] ans = new int[temperatures.length];
        for (int i = 0; i < temperatures.length; i++) {
            while (!stack.isEmpty() && temperatures[stack.peek()] < temperatures[i]) {
                int num = stack.pop();
                ans[num] = i - num;
            }
            stack.push(i);
        }
        return ans;
    }
}
